package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.component.MinioService;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dyqstart
 * @create 2021-08-03-0:26
 * @since 1.0.0
 */
@Api(tags = "品牌CRUD")
@RestController
@RequestMapping("/admin/product")
@Slf4j
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    @Autowired
    MinioService minioService;

    @ApiOperation("获取spu分页列表")
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result baseTrademarkPage(
            @ApiParam("当前页")
            @PathVariable("page") Long page,
            @ApiParam("页数")
            @PathVariable("limit") Long limit){

        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        Page<BaseTrademark> page1 = baseTrademarkService.page(baseTrademarkPage);

        return Result.ok(page1);
    }


    @ApiOperation("添加品牌")
    @PostMapping("baseTrademark/save")//tm_name  logo_url
    public Result baseTrademarkSave(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }


    @ApiOperation("修改品牌")
    @PutMapping("baseTrademark/update")
    public Result baseTrademarkUpload(@RequestBody BaseTrademark baseTrademark){
//        QueryWrapper<BaseTrademark> wrapper = new QueryWrapper<>();
//        wrapper.eq("id", baseTrademark.getId());
//        baseTrademarkService.update(wrapper);
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("根据Id获取品牌")
    @GetMapping("baseTrademark/get/{id}")
    public Result<BaseTrademark> baseTrademarkUpload(@PathVariable("id") Long id){

//        QueryWrapper<BaseTrademark> wrapper = new QueryWrapper<>();
//        wrapper.eq("id",id);
//
//        BaseTrademark baseTrademark = baseTrademarkService.getOne(wrapper);

        BaseTrademark baseTrademark = baseTrademarkService.getById(id);

        return Result.ok(baseTrademark);
    }

    @ApiOperation("根据Id删除品牌")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result baseTrademarkDelete(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("获取品牌属性")
    @GetMapping("baseTrademark/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }


}